package internact;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户管理类
 */
public class UserManager {
    private Map<String, String> users;
    private String currentUser;

    public UserManager() {
        users = new HashMap<>();
        users.put("user1", "password1");
        users.put("user2", "password2");
        currentUser = null;
    }

    public boolean login(String username, String password) {
        if (users.containsKey(username) && users.get(username).equals(password)) {
            currentUser = username;
            return true;
        } else {
            return false;
        }
    }

    public boolean register(String username, String password) {
        if (!users.containsKey(username)) {
            users.put(username, password);
            return true;
        } else {
            return false;
        }
    }

    public boolean modify(String username, String password) {
        if (users.containsKey(username)) {
            users.put(username, password);
            return true;
        } else {
            return false;
        }
    }

    public void logout() {
        currentUser = null;
    }

    public String getCurrentUser() {
        return currentUser;
    }
}

